/*******************************************************************************
* Copyright (c) 2012 
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* zhangliang - initial API and implementation
*******************************************************************************/

#ifndef TIMER_H
#define TIMER_H

#include "utils.h"
#include "singleton.h"

class Service;

/*!
 * @brief
 *  timers' manager, count base on milliseconds
 */
class Timers : public Singleton<Timers> {
 public:
  Timers(void);

  /*!
   * @brief
   *  add a timer
   * @param service
   *  ref of service
   * @param trigger_count
   *  the times this timer will be triggered
   *  0 for unlimited times
   * @param duration
   *  trigger duration
   * @param user_data
   *  user data that will be passed back to caller
   * @param timer_cb
   *  timer callback function addr
   *  note! must be raw function pointer, not class member function with vtable
   *  or some shit like that
   * @return 
   *  session id
   */
   uint32_t Add(Service& service, 
                uint32_t trigger_count,
                const utils::milliseconds& duration,
                void* user_data, 
                uintptr_t timer_cb);

  /*!
   * @brief
   *  timers' tick
   */
  void Tick(void);
  
 private:
  struct TimersImpl;
  boost::scoped_ptr<TimersImpl> pimpl_;
};

#endif // TIMER_H

